﻿using System;
using FU.Capstones.IMS.Web.Common;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.DataContracts;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.EventArgs;

namespace FU.Capstones.IMS.Web.Silverlight.Models
{
    public class PartnerListModel : ModelBase
    {
        public PartnerListModel()
        {
            client.DeletePartnerCompleted += DoDeleteCustomerCompleted;
            client.GetPartnerCollectionCompleted += DoGetPartnerCollectionCompleted;
            client.GetSinglePartnerCompleted += DoGetSingleCustomerCompleted;
            client.SearchPartnerCompleted += DoSearchPartnerCompleted;
            client.UndoDeletePartnerCompleted += DoUndoDeletePartnerCompleted;
        }

        #region UndoDeletePartner

        public event EventHandler<FeedbackCompletedEventArgs> UndoDeletePartnerCompleted;
        
        public int UndoDeletePartnerAsync(int objID)
        {
            client.UndoDeletePartnerAsync(objID);
            return WebConstants.MagicNumer;
        }
        
        void DoUndoDeletePartnerCompleted(object sender, FeedbackCompletedEventArgs e)
        {
            if (UndoDeletePartnerCompleted != null)
            {
                UndoDeletePartnerCompleted(sender, e);
            }
        }

        #endregion

        #region GetCustomerCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Partner>> GetPartnerCollectionCompleted;

        public int GetPartnerCollectionAsync(bool isShowAll)
        {
            client.GetPartnerCollectionAsync(isShowAll);   
            return WebConstants.MagicNumer;
        }

        void DoGetPartnerCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Partner> e)
        {
            if (GetPartnerCollectionCompleted != null)
            {
                GetPartnerCollectionCompleted(sender, e);
            }
        }

        #endregion
        
        #region SearchCustomer

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Partner>> SearhPartnerCompleted;

        public int SearchPartnerAsync(Partner criteria)
        {
            client.SearchPartnerAsync(criteria);
            return WebConstants.MagicNumer;
        }

        void DoSearchPartnerCompleted(object sender, CollectionFeedbackCompletedEventArgs<Partner> e)
        {
            if (SearhPartnerCompleted != null)
            {
                SearhPartnerCompleted(sender, e);
            }
        }

        #endregion

        #region DeleteCustomer

        public event EventHandler<FeedbackCompletedEventArgs> DeleteCustomerCompleted;

        public int DeleteCustomerAsync(int data)
        {
            client.DeletePartnerAsync(data);
            return WebConstants.MagicNumer;
        }

        void DoDeleteCustomerCompleted(object sender, FeedbackCompletedEventArgs e)
        {
            if (DeleteCustomerCompleted != null)
            {
                DeleteCustomerCompleted(sender, e);
            }
        }

        #endregion

        #region GetSingleCustomer

        public event EventHandler<SingleFeedbackCompletedEventArgs<Partner>> GetSingleCustomerCompleted;

        public int GetSingleCustomerAsync(int partnerID)
        {
            client.GetSinglePartnerAsync(partnerID);
            return WebConstants.MagicNumer;
        }

        void DoGetSingleCustomerCompleted(object sender, SingleFeedbackCompletedEventArgs<Partner> e)
        {
            if (GetSingleCustomerCompleted != null)
            {
                GetSingleCustomerCompleted(sender, e);
            }
        }

        #endregion
        
    }
}
